package com.vogtec.fota.entity.mqtt;

/**
 * Created by TieYan on 2017/3/4.
 */
public class BikeFota extends BikeWireDown {
    private byte type = 13;
    private String bikeNum;
    private byte protocol; // 0 http, 1 ftp
    private String url;

    public BikeFota(String bikeNum, byte protocol, String url) {
        this.bikeNum = bikeNum;
        this.protocol = protocol;
        this.url = url;
    }

    @Override
    public byte[] encode() {
        byte[] bikeNumBytes = Util.string2AsciiArray(bikeNum);

        byte[] content1 = Util.add(type, bikeNumBytes);

        byte[] content2 = Util.string2AsciiArray(url);
        int length = content2.length;
        byte[] content3 = {protocol, (byte)length};
        byte[] content4 = Util.add(content3, content2);
        content = Util.add(content1, content4);

        return content;
    }

    public static void main(String[] args){
        BikeFota bikeSMS = new BikeFota("12345678", (byte) 0, "http://rb.vogtec/com/1.bin");
        bikeSMS.encode();
        for(byte b: bikeSMS.content){
            System.out.println(b);
        }
//        int a = 200;
//        System.out.println((byte) a);

//        byte a = (byte)-56;
//        int i = a;
//        i = a&0xff;
//        System.out.println(i);
    }
}
